<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小黑的礼物清单</title>
</head>
<style>
    .father{
        width: 400px;
        margin: 10px auto;
        border: 1px solid #000;
    }
    .father td , th{
        border: 1px solid #000;
        text-align: center;
        font-size: 30px;
        font-weight: bold;
    }
    .total{
        text-align: center;
        font-size: 20px;
        font-weight: bold;
    }
</style>
<body>
    <div id = 'app'>
        <table class="father">
            <tr>
                <th>名字</th>
                <th>数量</th>
            </tr>
            <tr v-for="(item , index) in list" :key="item.id">
                <td>{{item.name}}</td>
                <td>{{item.num}}</td>
            </tr>
        </table>
        <div class="total">礼物总数：{{totalCount}}个</div>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
<script>
    const app = new Vue({
        el:'#app',
        data:{
            //现有的数据
            list:[
                { id : 1 , name : '篮球' , num: 1},
                { id : 2 , name : '铅笔' , num: 2},
                { id : 3 , name : '玩具' , num: 5}
            ]
        },
        computed:{
            totalCount(){
                let total = this.list.reduce((sum , item)=>sum + item.num , 0);
                return total ;
            }
        }
    })
</script>
</html>